<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="科研团队名称" prop="kytdMc">
        <el-input
          v-model="queryParams.kytdMc"
          placeholder="请输入科研团队名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="xmMc">
        <el-input
          v-model="queryParams.xmMc"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人员类别" prop="ryLb">
        <el-select v-model="queryParams.ryLb" placeholder="请选择人员类别" clearable>
          <el-option
            v-for="dict in dict.type.ry_lb"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="人员类型" prop="ryLx">
        <el-select v-model="queryParams.ryLx" placeholder="请选择人员类型" clearable>
          <el-option
            v-for="dict in dict.type.ry_lx"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="参会人" prop="chNam">
        <el-input
          v-model="queryParams.chNam"
          placeholder="请输入参会人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会议编号" prop="hyBh">
        <el-input
          v-model="queryParams.hyBh"
          placeholder="请输入会议编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会议名称" prop="hyMc">
        <el-input
          v-model="queryParams.hyMc"
          placeholder="请输入会议名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主办单位" prop="zbdw">
        <el-input
          v-model="queryParams.zbdw"
          placeholder="请输入主办单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参会日期" prop="chDate">
        <el-date-picker clearable
                        v-model="queryParams.chDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择参会日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:meeting:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:meeting:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:meeting:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:meeting:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="meetingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="学术活动分类" width="120"  align="center" prop="xshdFl">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.xshd_fl" :value="scope.row.xshdFl"/>
        </template>
      </el-table-column>
      <el-table-column label="科研团队类型" width="120"  align="center" prop="kytdLx">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.kytd_lx" :value="scope.row.kytdLx"/>
        </template>
      </el-table-column>
      <el-table-column label="科研团队代码" width="120"  align="center" prop="kytdDm" />
      <el-table-column label="科研团队名称" width="120"  align="center" prop="kytdMc" />
      <el-table-column label="项目编号" align="center" prop="xmNo" />
      <el-table-column label="项目名称" align="center" prop="xmMc" />
      <el-table-column label="人员类别" align="center" prop="ryLb">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ry_lb" :value="scope.row.ryLb"/>
        </template>
      </el-table-column>
      <el-table-column label="人员类型" align="center" prop="ryLx">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ry_lx" :value="scope.row.ryLx"/>
        </template>
      </el-table-column>
      <el-table-column label="参会人工号" width="120"  align="center" prop="chNo" />
      <el-table-column label="参会人" align="center" prop="chNam" />
      <el-table-column label="会议编号" align="center" prop="hyBh" />
      <el-table-column label="会议名称" align="center" prop="hyMc" />
      <el-table-column label="会议类型:" align="center" prop="hyLx">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hy_lx" :value="scope.row.hyLx"/>
        </template>
      </el-table-column>
      <el-table-column label="主办单位" align="center" prop="zbdw" />
      <el-table-column label="会议位置" align="center" prop="hyWz">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hy_wz" :value="scope.row.hyWz"/>
        </template>
      </el-table-column>
      <el-table-column label="参会日期" align="center" prop="chDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.chDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属单位" align="center" prop="ssdw" />
      <el-table-column label="详细信息" align="center" prop="xxInfo" />
      <el-table-column label="参会地址" align="center" prop="chdz" />
      <el-table-column label="提交论文篇数" width="120"  align="center" prop="tjlwNum" />
      <el-table-column label="特邀报告篇数" width="120"  align="center" prop="tybgNum" />
      <el-table-column label="论文题目" align="center" prop="lwTitle" />
      <el-table-column label="报告题目" align="center" prop="bgTitle" />
      <el-table-column label="会议简介" align="center" prop="hyRemark" />
      <el-table-column label="会议相关文档附件" width="140"  align="center" prop="hyFile" />
      <el-table-column label="说明" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:meeting:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:meeting:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改专家会议对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="组织机构ID" prop="deptId">
              <el-input v-model="form.deptId" placeholder="请输入组织机构ID" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学术活动分类" prop="xshdFl">
              <el-select v-model="form.xshdFl" placeholder="请选择学术活动分类">
                <el-option
                  v-for="dict in dict.type.xshd_fl"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="科研团队类型" prop="kytdLx">
              <el-select v-model="form.kytdLx" placeholder="请选择科研团队类型">
                <el-option
                  v-for="dict in dict.type.kytd_lx"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="科研团队代码" prop="kytdDm">
              <el-input v-model="form.kytdDm" placeholder="请输入科研团队代码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="科研团队名称" prop="kytdMc">
              <el-input v-model="form.kytdMc" placeholder="请输入科研团队名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目编号" prop="xmNo">
              <el-input v-model="form.xmNo" placeholder="请输入项目编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="xmMc">
              <el-input v-model="form.xmMc" placeholder="请输入项目名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="人员类别" prop="ryLb">
              <el-select v-model="form.ryLb" placeholder="请选择人员类别">
                <el-option
                  v-for="dict in dict.type.ry_lb"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="人员类型" prop="ryLx">
              <el-select v-model="form.ryLx" placeholder="请选择人员类型">
                <el-option
                  v-for="dict in dict.type.ry_lx"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="参会人工号" prop="chNo">
              <el-input v-model="form.chNo" placeholder="请输入参会人工号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="参会人" prop="chNam">
              <el-input v-model="form.chNam" placeholder="请输入参会人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="会议编号" prop="hyBh">
              <el-input v-model="form.hyBh" placeholder="请输入会议编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="会议名称" prop="hyMc">
              <el-input v-model="form.hyMc" placeholder="请输入会议名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="会议类型:" prop="hyLx">
              <el-select v-model="form.hyLx" placeholder="请选择会议类型:">
                <el-option
                  v-for="dict in dict.type.hy_lx"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="主办单位" prop="zbdw">
              <el-input v-model="form.zbdw" placeholder="请输入主办单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="会议位置" prop="hyWz">
              <el-select v-model="form.hyWz" placeholder="请选择会议位置">
                <el-option
                  v-for="dict in dict.type.hy_wz"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="参会日期" prop="chDate">
              <el-date-picker clearable
                              v-model="form.chDate"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择参会日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属单位" prop="ssdw">
              <el-input v-model="form.ssdw" placeholder="请输入所属单位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="详细信息" prop="xxInfo">
              <el-input v-model="form.xxInfo" placeholder="请输入详细信息" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="参会地址" prop="chdz">
              <el-input v-model="form.chdz" placeholder="请输入参会地址" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="提交论文篇数" prop="tjlwNum">
              <el-input v-model="form.tjlwNum" placeholder="请输入提交论文篇数" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="特邀报告篇数" prop="tybgNum">
              <el-input v-model="form.tybgNum" placeholder="请输入特邀报告篇数" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="论文题目" prop="lwTitle">
              <el-input v-model="form.lwTitle" placeholder="请输入论文题目" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报告题目" prop="bgTitle">
              <el-input v-model="form.bgTitle" placeholder="请输入报告题目" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="会议简介" prop="hyRemark">
              <el-input v-model="form.hyRemark" placeholder="请输入会议简介" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="会议相关文档附件">
              <file-upload v-model="form.hyFile"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="说明" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listMeeting, getMeeting, delMeeting, addMeeting, updateMeeting } from "@/api/pm/meeting";

  export default {
    name: "Meeting",
    dicts: ['ry_lb', 'hy_lx', 'ry_lx', 'xshd_fl', 'hy_wz', 'kytd_lx'],
    data() {
      return {
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 专家会议表格数据
        meetingList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          kytdMc: undefined,
          xmMc: undefined,
          ryLb: undefined,
          ryLx: undefined,
          chNam: undefined,
          hyBh: undefined,
          hyMc: undefined,
          zbdw: undefined,
          chDate: undefined,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          xmMc: [
            { required: true, message: "项目名称不能为空", trigger: "blur" }
          ],
          ryLb: [
            { required: true, message: "人员类别不能为空", trigger: "change" }
          ],
          ryLx: [
            { required: true, message: "人员类型不能为空", trigger: "change" }
          ],
          chNam: [
            { required: true, message: "参会人不能为空", trigger: "blur" }
          ],
          hyBh: [
            { required: true, message: "会议编号不能为空", trigger: "blur" }
          ],
          hyMc: [
            { required: true, message: "会议名称不能为空", trigger: "blur" }
          ],
          hyLx: [
            { required: true, message: "会议类型:不能为空", trigger: "change" }
          ],
          zbdw: [
            { required: true, message: "主办单位不能为空", trigger: "blur" }
          ],
          hyWz: [
            { required: true, message: "会议位置不能为空", trigger: "change" }
          ],
          chDate: [
            { required: true, message: "参会日期不能为空", trigger: "blur" }
          ],
          remark: [
            { required: true, message: "说明不能为空", trigger: "blur" }
          ]
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询专家会议列表 */
      getList() {
        this.loading = true;
        listMeeting(this.queryParams).then(response => {
          this.meetingList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          deptId: undefined,
          xshdFl: undefined,
          kytdLx: undefined,
          kytdDm: undefined,
          kytdMc: undefined,
          xmNo: undefined,
          xmMc: undefined,
          ryLb: undefined,
          ryLx: undefined,
          chNo: undefined,
          chNam: undefined,
          hyBh: undefined,
          hyMc: undefined,
          hyLx: undefined,
          zbdw: undefined,
          hyWz: undefined,
          chDate: undefined,
          ssdw: undefined,
          xxInfo: undefined,
          chdz: undefined,
          tjlwNum: undefined,
          tybgNum: undefined,
          lwTitle: undefined,
          bgTitle: undefined,
          hyRemark: undefined,
          hyFile: undefined,
          createBy: undefined,
          createTime: undefined,
          updateBy: undefined,
          updateTime: undefined,
          remark: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加专家会议";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.loading = true;
        this.reset();
        const id = row.id || this.ids
        getMeeting(id).then(response => {
          this.loading = false;
          this.form = response.data;
          this.open = true;
          this.title = "修改专家会议";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.form.id != null) {
              updateMeeting(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addMeeting(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除专家会议编号为"' + ids + '"的数据项？').then(() => {
          this.loading = true;
          return delMeeting(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        }).finally(() => {
          this.loading = false;
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('business/meeting/export', {
          ...this.queryParams
        }, `meeting_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
